// pages/displayContent/displayContent.js
// pages/patrolLog/patrolLog.js  
const app = getApp()
const util = require('../../utils/util.js')
var BLELocker = require("../../utils/BLELocker.js")
var blueConStatHandler = require("../../utils/blueConStatHandler.js")
var Base64 = require('../../utils/base64.js')
const lbbService = require('../service/service.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false, //控制下拉列表的显示隐藏，false隐藏、true显示
    selectData: ['3', '5', '8', '10', '15', '20'], //下拉列表的数据
    index: 0 //选择的下拉列表下标
  },
  // 点击下拉显示框
  selectTap() {
    this.setData({
      show: !this.data.show
    });
  },
  // 点击下拉列表
  optionTap(e) {
    let Index = e.currentTarget.dataset.index; //获取点击的下拉列表的下标
    this.setData({
      index: Index,
      show: !this.data.show
    });
  },
    /**
   * 重试95
   */ 
  retry95() {
    let that = this;
    that.hideModal1();
    that.setData({
      loading_show: true,
      loading_desc: "数据读取中"
    });
    BLELocker.send95Command(function (isSuccess) {
      if (isSuccess == false) {
        that.getConnect(that.data.macId);
      } else {
        that.uploadAndGet();
      }
    })
  },
    /**
   * 重试蓝牙连接
   */
  retryConnect() {
    let that = this;
    that.hideModal1();
    that.setData({
      loading_show: true,
      loading_desc: "设备连接中"
    });
    that.getConnect(that.data.macId);
  },
  getConnect: function (mac_id) {
    let macId = mac_id || that.data.macId
    let that = this
    that.setData({
      loading_show: true,
      loading_desc: '设备连接中...'
    })
    if (that.data.newConFlg) {
      BLELocker.newConnect('DK' + macId, function (status, data) {
        blueConStatHandler.handleStatus(status, data, that, that.uploadAndGet, true)
      }, 0, false, null, null, that);
    } else {
      BLELocker.directConnect('DK' + macId, function (status, data) {
        blueConStatHandler.handleStatus(status, data, that, that.uploadAndGet, true)
      }, 0, false, null, null, that);
    };
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})